package com.similarworld.util;

import org.springframework.security.core.context.SecurityContextHolder;

import com.similarworld.model.User;
import com.similarworld.type.UserType;

public class SecurityUtils {
	
	public static User getLoginUser() {
		return (User) SecurityContextHolder.getContext().
				getAuthentication().getPrincipal();
	}
	
	public static boolean isUserLogin() {
		try {
			User user = (User) SecurityContextHolder.getContext().
			getAuthentication().getPrincipal();
			if(user != null) return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}
	
	public static boolean isUserSuperUser() {
		User user =  (User) SecurityContextHolder.getContext().
				getAuthentication().getPrincipal();
		if(UserType.SUPERUSER.equals(user.getType())) {
			return true;
		}
		return false;
	}
	
	public static boolean isUserAdmin() {
		User user =  (User) SecurityContextHolder.getContext().
				getAuthentication().getPrincipal();
		if(UserType.ADMIN.equals(user.getType())) {
			return true;
		}
		return false;
	}

}
